import request from '.'

interface ApiResponse<T = unknown> {
  code: number
  data: T
  message: string
}

export const getI18nList = <T>(data: { current: string; currentSize: string }) => {
  const usp = new URLSearchParams(data)
  return request.get(`/i18n/list?${usp.toString()}`) as Promise<ApiResponse<T>>
}

export const deleteI18nItem = <T>(code: string) => {
  return request.delete(`/i18n/delete/${code}`) as Promise<ApiResponse<T>>
}

interface I18nItem {
  code: string
  languageTexts: { languageTag: string; message: string }[]
  remarks: string
}

export const createI18nItem = <T>(data: I18nItem) => {
  return request.post(`/i18n/create`, data) as Promise<ApiResponse<T>>
}

export const updateI18nItem = <T>(data: I18nItem) => {
  return request.post('/i18n/update', data) as Promise<ApiResponse<T>>
}

export const importI18nItem = <T>(formData: FormData, format?: string) => {
  // 如果指定了格式，添加到FormData中
  if (format) {
    formData.append('format', format);
  }
  
  return request.post('/i18n/import', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  }) as Promise<ApiResponse<T>>
}
